package algorithm_demo.leetcode;

/**
 * 26. 删除有序数组中的重复项
 * <a href="https://leetcode.cn/problems/remove-duplicates-from-sorted-array/">https://leetcode.cn/problems/remove-duplicates-from-sorted-array/</a>
 * @author Api
 * @date 2023/5/7 16:47
 */
public class Problem_026_RemoveDuplicatesFromSortedArray {
    public static int removeDuplicates(int[] nums) {
        int i = 0;//i表示慢指针
        for(int j = 0; j < nums.length; j++){ // j表示快指针
            if (nums[j] != nums[i]){
                i++;
                nums[i] = nums[j];
            }
        }
        i++;
        return i;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1,1,2,3,3,4,4,6,7,7};
        int ans = removeDuplicates(arr);
        System.out.println(ans);
    }
}
